<template>
	<div class="dialog-container">
		<el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" :close-on-click-modal="false" width="500px">
			<template #footer>
				<el-button @click="onCancel" size="default">取 消</el-button>
				<el-button type="primary" @click="onSubmit" :loading="state.dialog.submitLoading" size="default">提 交</el-button>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" name="templateDialog" setup>
import { reactive } from 'vue';

let callback: Function = () => {};
const state = reactive({
	dialog: {
		isShowDialog: false,
		type: '',
		title: '',
		submitLoading: false,
	},
});

/********** 触发事件 **********/
// 取消
const onCancel = () => {
	state.dialog = {
		isShowDialog: false,
		type: '',
		title: '',
		submitLoading: false,
	};
};
// 提交
const onSubmit = () => {
	onCancel();
	callback();
};

/********** 方法事件 **********/
// 打开
const openDialog = (config:any, fn: Function) => {
	state.dialog.isShowDialog = true;
	callback = fn;
};

/********** 网络请求 **********/

/********** 方法向父组件暴露 **********/
defineExpose({ openDialog });
</script>
